package com.jeecg.guangdian.controller;

import com.alibaba.fastjson.JSON;
import com.jeecg.guangdian.entity.BusinessOrderEntity;
import com.jeecg.guangdian.entity.ChartReport;
import com.jeecg.guangdian.service.BusinessOrderServiceI;
import com.jeecg.guangdian.service.BusinessUserMapServiceI;
import com.jeecg.guangdian.util.CommonUtil;
import com.jeecg.guangdian.util.CreateExcelFile;
import com.jeecg.guangdian.util.SysContent;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.MyBeanUtils;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.jeecgframework.web.system.pojo.base.TSRoleUser;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.service.SystemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;


/**   
 * @Title: Controller  
 * @Description: 稿费订单表
 * @author onlineGenerator
 * @date 2019-07-23 14:07:00
 * @version V1.0   
 *
 */
@Controller
@RequestMapping("/businessOrderController")
public class BusinessOrderController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(BusinessOrderController.class);

	@Autowired
	private BusinessOrderServiceI businessOrderService;
	@Autowired
	private SystemService systemService;
	@Autowired
	private BusinessUserMapServiceI businessUserMapService;


	/**
	 * 稿费订单表列表 页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "list")
	public ModelAndView list(HttpServletRequest request) {
		String orgCode = String.valueOf(request.getParameter("orgCode"));
		String orgType = String.valueOf(request.getParameter("orgType"));
		String orgParent = String.valueOf(null==request.getParameter("orgParent")?"":request.getParameter("orgParent"));
		request.setAttribute("orgCode",orgCode);
		request.setAttribute("orgType",orgType);
		request.setAttribute("orgParent",orgParent);
		String startdt = CommonUtil.getCurrentDate("yyyy-MM-01");
		String enddt  = CommonUtil.getCurrentDate("yyyy-MM-dd");
		request.setAttribute("startdt",startdt);
		request.setAttribute("enddt",enddt);
		TSUser user = ResourceUtil.getSessionUser();
		request.setAttribute("buttons",null==request.getSession().getAttribute("buttons"+user.getId())?"":request.getSession().getAttribute("buttons"+user.getId()));
		return new ModelAndView("com/jeecg/guangdian/businessOrderList");
	}

	/**
	 * easyui AJAX请求数据
	 * 
	 * @param request
	 * @param response
	 * @param dataGrid
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(BusinessOrderEntity businessOrder,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(BusinessOrderEntity.class, dataGrid);
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, businessOrder, request.getParameterMap());
		this.orgCq(cq,request,null);
		cq.eq("uflag", "1");
		cq.addOrder("number", SortDirection.asc);
		String startdt = request.getParameter("createDate_begin");
		String enddt = request.getParameter("createDate_end");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		if(!StringUtils.isEmpty(startdt)){
			cq.gt("createDate", CommonUtil.strToDateLong(startdt));
		}
		if(!StringUtils.isEmpty(enddt)){
			cq.lt("createDate",CommonUtil.strToDateLong(enddt));
		}
		cq.add();
		this.businessOrderService.getDataGridReturn(cq, true);
		StringBuffer totleSql = new StringBuffer();
		totleSql.append("select sum(ucost) from business_order o where 1=1 ");
		String orgCode = String.valueOf(null==request.getParameter("orgCode")?"":request.getParameter("orgCode"));
		String orgType = String.valueOf(null==request.getParameter("orgType")?"":request.getParameter("orgType"));
		if("0".equals(orgType)){
			totleSql.append(" and sys_org_code='"+orgCode+"'");
		}else if("1".equals(orgType)){
			totleSql.append(" and sys_company_code='"+orgCode+"'");
		}
		this.orgsql(totleSql,request,null);
		totleSql.append(" and uflag = 1 ");
		totleSql.append(" and o.create_date >='").append(startdt).append("' ");
		totleSql.append(" and o.create_date <='").append(enddt).append("' ");
		try{
			Long totle = this.systemService.getCountForJdbc(totleSql.toString());
			dataGrid.setFooter("userCard:合计,ucost:"+(null==totle?0:totle)+"");
		}catch (Exception e){
		}
		TagUtil.datagrid(response, dataGrid);
	}
	@RequestMapping(params = "addDatagrid")
	public void addDatagrid(BusinessOrderEntity businessOrder,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(BusinessOrderEntity.class, dataGrid);
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, businessOrder, request.getParameterMap());
		Map<String,String> deptMap = new HashMap<>();
		this.orgCq(cq,request,deptMap);
		cq.eq("uflag", "0");
		cq.addOrder("createDate", SortDirection.desc);
		String startdt = request.getParameter("createDate_begin");
		String enddt = request.getParameter("createDate_end");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		cq.gt("createDate", CommonUtil.strToDateLong(startdt));
		cq.lt("createDate",CommonUtil.strToDateLong(enddt));
		cq.eq("createBy",ResourceUtil.getSessionUser().getUserName());
		cq.add();
		this.businessOrderService.getDataGridReturn(cq, true);
		List<BusinessOrderEntity> list = dataGrid.getResults();
		for(int i=0;i<list.size();i++){
			list.get(i).setSysOrgCode(deptMap.get(list.get(i).getSysOrgCode()));
			list.get(i).setSysCompanyCode(deptMap.get(list.get(i).getSysCompanyCode()));
		}
		TagUtil.datagrid(response, dataGrid);
	}
	@RequestMapping(params = "chart")
	public void chart(BusinessOrderEntity businessOrder,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		StringBuffer queryDetail = new StringBuffer();
		String orgCode = String.valueOf(null==request.getParameter("orgCode")?"":request.getParameter("orgCode"));
		String orgType = String.valueOf(null==request.getParameter("orgType")?"":request.getParameter("orgType"));
		if("0".equals(orgType)){
			queryDetail.append("select o.sys_company_code as userName,cast(sum(o.ucost) as char) as ucost from business_order o where 1=1 ");
		}else if("1".equals(orgType)){
			queryDetail.append("select o.user_name as userName,cast(sum(o.ucost) as char) as ucost from business_order o where 1=1 ");
		}else{
			queryDetail.append("select o.sys_org_code as userName,cast(sum(o.ucost) as char) as ucost from business_order o where 1=1 ");
		}

		if("0".equals(orgType)){
			queryDetail.append(" and sys_org_code='"+orgCode+"'");
		}else if("1".equals(orgType)){
			queryDetail.append(" and sys_company_code='"+orgCode+"'");
		}
		Map<String,String> deptMap = new HashMap<>();
		this.orgsql(queryDetail,request,deptMap);
		queryDetail.append(" and o.uflag = 1");
		//处理时间，当前月
		String startdt = request.getParameter("startdt");
		String enddt = request.getParameter("enddt");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		queryDetail.append(" and o.create_date >='").append(startdt).append("' ");
		queryDetail.append(" and o.create_date <='").append(enddt).append("' ");
		if("0".equals(orgType)){
			queryDetail.append(" group by o.sys_company_code");
		}else if("1".equals(orgType)){
			queryDetail.append(" group by o.user_name,o.user_card");
		}else{
			queryDetail.append(" group by o.sys_org_code");
		}

		List<BusinessOrderEntity> details = systemService.findObjForJdbc(queryDetail.toString(),1,10000,BusinessOrderEntity.class);
		List<String> title = new ArrayList<>();
		List<String> realdt = new ArrayList<>();
		for(int i=0;i<details.size();i++){
			if(!"1".equals(orgType)){
				details.get(i).setUserName(deptMap.get(details.get(i).getUserName()));
			}
			title.add(details.get(i).getUserName());
			realdt.add(details.get(i).getUcost());
		}
		ChartReport chartReport = new ChartReport();
		Map<String, Object> legend = new HashMap<>();
		legend.put("show","false");
		legend.put("x","center");
		legend.put("y","bottom");
		List<String> dt = new ArrayList<>();
		dt.add("稿费");
		legend.put("data",dt);
		chartReport.setLegend(legend);
		List<Map<String,Object>> xAxis = new ArrayList<>();
		Map<String,Object> xaxis = new HashMap<>();
		xaxis.put("type","category");
		xaxis.put("data",title);
		xAxis.add(xaxis);
		chartReport.setxAxis(xAxis);
		List<Map<String,Object>> series =  new ArrayList<>();
		Map<String,Object> seriemap = new HashMap<>();
		seriemap.put("data",realdt);
		seriemap.put("name","稿费");
		seriemap.put("type","bar");
		seriemap.put("barWidth","20");
		series.add(seriemap);
		chartReport.setSeries(series);
		PrintWriter out = null;
		try {
			response.setCharacterEncoding("utf-8");
			out = response.getWriter();
			out.print(JSON.toJSONString(chartReport));
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@RequestMapping(params = "checkListDatagrid")
	public void checkListDatagrid(BusinessOrderEntity businessOrder, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(BusinessOrderEntity.class, dataGrid);
		Map<String,String> deptMap = new HashMap<>();
		this.orgCq(cq,request,deptMap);
		cq.addOrder("createTime", SortDirection.desc);
		TSUser user = ResourceUtil.getSessionUser();
		List<TSRoleUser> rUsers = systemService.findByProperty(TSRoleUser.class, "TSUser.id", user.getId());
		if(!CollectionUtils.isEmpty(rUsers)){
			String code = rUsers.get(0).getTSRole().getRoleCode();
			//查全部
			if("admin".equals(code)){
			}if("check".equals(code)){
				//默认没时间
				cq.eq("uflag", "0");
			}else if("checkm".equals(code)){
				if(null==request.getParameterMap().get("createTime_begin")&&null==request.getParameterMap().get("createTime_end")){
					cq.gt("createDate",CommonUtil.strToDateLong(CommonUtil.getoutstartday(SysContent.dayOut)+" 00:00:00"));
					cq.lt("createDate",CommonUtil.strToDate(CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59"));
				}
				//上个月1号到这个月
				cq.eq("uflag", "1");
			}else{
				//根据传入时间
			}
		}
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, businessOrder, request.getParameterMap());
		this.businessOrderService.getDataGridReturn(cq, true);
		List<BusinessOrderEntity> list = dataGrid.getResults();
		for(int i=0;i<list.size();i++){
			list.get(i).setSysOrgCode(deptMap.get(list.get(i).getSysOrgCode()));
			list.get(i).setSysCompanyCode(deptMap.get(list.get(i).getSysCompanyCode()));
		}
		TagUtil.datagrid(response, dataGrid);
	}
	@RequestMapping(params = "exportDatagrid")
	public void exportDatagrid(BusinessOrderEntity businessOrder, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		String detailflag = request.getParameter("detailflag");
		if(null==detailflag||"".equals(detailflag)){
			detailflag = "1";
		}
		if(StringUtils.isBlank(businessOrder.getSysOrgCode())&&StringUtils.isBlank(businessOrder.getSysCompanyCode())){
			if("1"==request.getParameter("orgTypeInit")){
				businessOrder.setSysCompanyCode(request.getParameter("orgCodeInit"));
			}else if("0"==request.getParameter("orgTypeInit")){
				businessOrder.setSysOrgCode(request.getParameter("orgCodeInit"));
			}
		}
		Map<String,String> deptMap = new HashMap<>();
		StringBuffer queryDetail = new StringBuffer();
		StringBuffer detailbf = new StringBuffer();
		StringBuffer countbf = new StringBuffer();
		if("1".equals(detailflag)){
			countbf.append("select * from (select count(1) from business_order o WHERE 1 = 1 ");
			detailbf.append("SELECT o.id,o.number AS number,o.sys_org_code AS sysOrgCode,o.user_name AS userName,o.user_card AS userCard,o.cost_type AS costType,o.ucost AS ucost,o.cost_addr AS costAddr,o.cost_putout AS costPutout,o.contribution AS contribution,o.sys_company_code AS sysCompanyCode,o.column_time AS columnTime,o.column_num AS columnNum FROM business_order o WHERE 1 = 1 ");
		}else{
			countbf.append("select count(1) from (select 1 from business_order o WHERE 1 = 1 ");
			detailbf.append("SELECT max(o.id) id,max(o.number) AS number,max(o.sys_org_code) AS sysOrgCode,max(o.user_name) AS userName,o.user_card AS userCard,max(o.cost_type) AS costType,cast(sum(o.ucost) as char) AS ucost,max(o.cost_addr) AS costAddr,max(o.cost_putout) AS costPutout,max(o.contribution) AS contribution,max(o.sys_company_code) AS sysCompanyCode,max(o.column_time) AS columnTime,cast(sum(cast(o.column_num as SIGNED)) as CHAR) AS columnNum FROM business_order o WHERE 1 = 1 ");
		}

		this.orgsql(queryDetail,request,deptMap);
		if(!StringUtils.isBlank(businessOrder.getSysOrgCode())){
			queryDetail.append(" and sys_org_code='"+businessOrder.getSysOrgCode()+"'");
		}
		if(!StringUtils.isBlank(businessOrder.getSysCompanyCode())){
			queryDetail.append(" and sys_company_code='"+businessOrder.getSysCompanyCode()+"'");
		}
		if(StringUtils.isBlank(businessOrder.getSysOrgCode())&&StringUtils.isBlank(businessOrder.getSysCompanyCode())){
			String orgCode = String.valueOf(null==request.getParameter("orgCode")?"":request.getParameter("orgCode"));
			String orgType = String.valueOf(null==request.getParameter("orgType")?"":request.getParameter("orgType"));
			if("0".equals(orgType)){
				queryDetail.append(" and sys_org_code='"+orgCode+"'");
			}else if("1".equals(orgType)){
				queryDetail.append(" and sys_company_code='"+orgCode+"'");
			}
		}
		if(!StringUtils.isEmpty(businessOrder.getCostType())){
			queryDetail.append(" and cost_type='"+businessOrder.getCostType()+"'");
		}
		//处理时间，当前月
		String startdt = request.getParameter("startdt");
		String enddt = request.getParameter("enddt");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		queryDetail.append(" and o.create_date >='").append(startdt).append("' ");
		queryDetail.append(" and o.create_date <='").append(enddt).append("' ");
		if("1".equals(detailflag)){
			queryDetail.append(" and o.uflag = 1 ");
		}else{
			queryDetail.append(" and o.uflag = 1 group by o.user_card ");
		}
		String execdetail = detailbf.append(queryDetail).toString();//.append(" limit ").append(dataGrid.getRows()*(dataGrid.getPage()-1)).append(",").append(dataGrid.getRows()).toString();
		List<BusinessOrderEntity> details = systemService.findObjForJdbc(execdetail,dataGrid.getPage()<1?1:dataGrid.getPage(),dataGrid.getRows(),BusinessOrderEntity.class);
		for(int i=0;i<details.size();i++){
			details.get(i).setSysOrgCode(deptMap.get(details.get(i).getSysOrgCode()));
			details.get(i).setSysCompanyCode(deptMap.get(details.get(i).getSysCompanyCode()));
		}

		Long detailcount = systemService.getCountForJdbcParam(countbf.append(queryDetail).toString()+")z");
		dataGrid.setResults(details);
		dataGrid.setTotal(detailcount.intValue());
		TagUtil.datagrid(response, dataGrid);
	}
	@RequestMapping(params = "topcheckDatagrid")
	public void topcheckDatagrid(BusinessOrderEntity businessOrder, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		String detailflag = request.getParameter("detailflag");
		if(null==detailflag||"".equals(detailflag)){
			detailflag = "1";
		}
		Map<String,String> deptMap = new HashMap<>();
		StringBuffer queryDetail = new StringBuffer();
		StringBuffer detailbf = new StringBuffer();
		StringBuffer countbf = new StringBuffer();
		if("1".equals(detailflag)){
			countbf.append("select * from (select count(1) from business_order o WHERE 1 = 1 ");
			detailbf.append("SELECT o.id,o.number AS number,o.sys_org_code AS sysOrgCode,o.user_name AS userName,o.user_card AS userCard,o.cost_type AS costType,o.ucost AS ucost,o.cost_addr AS costAddr,o.cost_putout AS costPutout,o.contribution AS contribution,o.sys_company_code AS sysCompanyCode,o.column_time AS columnTime,o.column_num AS columnNum,o.u_log as uLog FROM business_order o WHERE 1 = 1 ");
		}else{
			countbf.append("select count(1) from (select 1 from business_order o WHERE 1 = 1 ");
			detailbf.append("SELECT max(o.id) id,max(o.number) AS number,max(o.sys_org_code) AS sysOrgCode,max(o.user_name) AS userName,o.user_card AS userCard,max(o.cost_type) AS costType,cast(sum(o.ucost) as char) AS ucost,max(o.cost_addr) AS costAddr,max(o.cost_putout) AS costPutout,max(o.contribution) AS contribution,max(o.sys_company_code) AS sysCompanyCode,max(o.column_time) AS columnTime,cast(sum(cast(o.column_num as SIGNED)) as CHAR) AS columnNum,max(o.u_log) as uLog  FROM business_order o WHERE 1 = 1 ");
		}
		//处理时间，当前月
		String startdt = request.getParameter("startdt");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		queryDetail.append(" and o.create_date >='").append(startdt).append("' ");
		String enddt = request.getParameter("enddt");
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		queryDetail.append(" and o.create_date <='").append(enddt).append("' ");
		if(!StringUtils.isEmpty(businessOrder.getUserCard())){
			queryDetail.append(" and o.user_card like '%").append(businessOrder.getUserCard()).append("%'");
		}
		this.orgsql(queryDetail,null,deptMap);
		if("1".equals(detailflag)){
			queryDetail.append(" and o.uflag = 1  order by o.number");
		}else{
			queryDetail.append(" and o.uflag = 1 group by o.user_card  order by MAX(o.number)");
		}

		String execdetail = detailbf.append(queryDetail).toString();//.append(" limit ").append(dataGrid.getRows()*(dataGrid.getPage()-1)).append(",").append(dataGrid.getRows()).toString();
		List<BusinessOrderEntity> details = systemService.findObjForJdbc(execdetail,dataGrid.getPage()<1?1:dataGrid.getPage(),dataGrid.getRows(),BusinessOrderEntity.class);
		for(int i=0;i<details.size();i++){
			details.get(i).setSysOrgCode(deptMap.get(details.get(i).getSysOrgCode()));
			details.get(i).setSysCompanyCode(deptMap.get(details.get(i).getSysCompanyCode()));
		}
		Long detailcount = systemService.getCountForJdbcParam(countbf.append(queryDetail).toString()+")z");
		dataGrid.setResults(details);
		dataGrid.setTotal(detailcount.intValue());
		TagUtil.datagrid(response, dataGrid);
	}
	@RequestMapping(params = "topcheckExcel")
	public void topcheckExcel(BusinessOrderEntity businessOrder, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception{
		String detailflag = request.getParameter("detailflag");
		if(null==detailflag||"".equals(detailflag)){
			detailflag = "1";
		}
		Map<String,String> deptMap = new HashMap<>();
		StringBuffer queryDetail = new StringBuffer();
		StringBuffer detailbf = new StringBuffer();
		if("1".equals(detailflag)){
			detailbf.append("SELECT o.id,o.number AS number,o.sys_org_code AS sysOrgCode,o.user_name AS userName,o.user_card AS userCard,o.cost_type AS costType,o.ucost AS ucost,o.cost_addr AS costAddr,o.cost_putout AS costPutout,o.contribution AS contribution,o.sys_company_code AS sysCompanyCode,o.column_time AS columnTime,o.column_num AS columnNum,o.u_log as uLog FROM business_order o WHERE 1 = 1 ");
		}else{
			detailbf.append("SELECT max(o.id) id,max(o.number) AS number,max(o.sys_org_code) AS sysOrgCode,max(o.user_name) AS userName,o.user_card AS userCard,max(o.cost_type) AS costType,cast(sum(o.ucost) as char) AS ucost,max(o.cost_addr) AS costAddr,max(o.cost_putout) AS costPutout,max(o.contribution) AS contribution,max(o.sys_company_code) AS sysCompanyCode,max(o.column_time) AS columnTime,cast(sum(cast(o.column_num as SIGNED)) as CHAR) AS columnNum,max(o.u_log) as uLog  FROM business_order o WHERE 1 = 1 ");
		}
		//处理时间，当前月
		String startdt = request.getParameter("startdt");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		queryDetail.append(" and o.create_date >='").append(startdt).append("' ");
		String enddt = request.getParameter("enddt");
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		queryDetail.append(" and o.create_date <='").append(enddt).append("' ");
		if(!StringUtils.isEmpty(businessOrder.getUserCard())){
			queryDetail.append(" and o.user_card like '%").append(businessOrder.getUserCard()).append("%'");
		}
		this.orgsql(queryDetail,null,deptMap);
		if("1".equals(detailflag)){
			queryDetail.append(" and o.uflag = 1  order by o.number");
		}else{
			queryDetail.append(" and o.uflag = 1 group by o.user_card  order by MAX(o.number)");
		}
		String execdetail = detailbf.append(queryDetail).toString();//.append(" limit ").append(dataGrid.getRows()*(dataGrid.getPage()-1)).append(",").append(dataGrid.getRows()).toString();
		List<BusinessOrderEntity> details = systemService.findObjForJdbc(execdetail,dataGrid.getPage()<1?1:dataGrid.getPage(),dataGrid.getRows(),BusinessOrderEntity.class);
		for(int i=0;i<details.size();i++){
			details.get(i).setSysOrgCode(deptMap.get(details.get(i).getSysOrgCode()));
			details.get(i).setSysCompanyCode(deptMap.get(details.get(i).getSysCompanyCode()));
		}

// 创建 Excel 文件， 文件名为打点信息， 表名为打点统计表
		CreateExcelFile excelFile = new CreateExcelFile("稿费演播费管理系统", startdt.substring(0,10)+"至"+enddt.substring(0,10)+"明细导出",
				request,response);
		// 设置单元格的右对齐格式
		HSSFCellStyle rightStyle = excelFile.createCellStyle();
		rightStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
		// 设置单元格的左对齐格式
		HSSFCellStyle leftStyle = excelFile.createCellStyle();
		leftStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		// 设置单元格的居中对齐文本格式
		HSSFCellStyle centerStyle = excelFile.createCellStyle();
		centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		// 设置列宽
		excelFile.setColWidth(0, 5);
		excelFile.setColWidth(1, 25);
		excelFile.setColWidth(2, 25);
		excelFile.setColWidth(3, 25);
		excelFile.setColWidth(4, 25);
		excelFile.setColWidth(5, 25);
		excelFile.setColWidth(6, 25);
		excelFile.setColWidth(7, 25);
		excelFile.setColWidth(8, 25);
		excelFile.setColWidth(9, 25);
		excelFile.setColWidth(10, 25);
		excelFile.setColWidth(11, 25);
		// 向Excel文件中的第一行添加表头
		excelFile.addText(0, 0,"序号", centerStyle);
		excelFile.addText(1, 0,"频道名称", centerStyle);
		excelFile.addText(2, 0,"姓名", centerStyle);
		excelFile.addText(3, 0,"身份证号", centerStyle);

		excelFile.addText(4, 0,"费用类型", centerStyle);
		excelFile.addText(5, 0,"金额", centerStyle);
		excelFile.addText(6, 0,"汇款地址/账号", centerStyle);
		excelFile.addText(7, 0,"发放方式", centerStyle);
		excelFile.addText(8, 0,"稿件题目(内容)", centerStyle);
		excelFile.addText(9, 0,"栏目名称", centerStyle);
		excelFile.addText(10, 0,"播出时间", centerStyle);
		excelFile.addText(11, 0,"字数/时长/版面", centerStyle);

		String temp = null;
		BusinessOrderEntity orderExcel=null;
		if (null != details && !(details.isEmpty())) {
			// 遍历检索结果列表，向 Excel 文件依次添加记录
			for (int i = 0; i < details.size(); i++) {
				orderExcel =  details.get(i);

				temp = (String) orderExcel.getNumber();
				excelFile.addText(0, i + 1, temp, centerStyle);

				temp = (String) orderExcel.getSysOrgCode();
				excelFile.addText(1, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getUserName();
				excelFile.addText(2, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getUserCard();
				excelFile.addText(3, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getCostType();
				excelFile.addText(4, i + 1, temp, leftStyle);

				temp = String.valueOf(orderExcel.getUcost());
				excelFile.addText(5, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getCostAddr();
				excelFile.addText(6, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getCostPutout();
				excelFile.addText(7, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getContribution();
				excelFile.addText(8, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getSysCompanyCode();
				excelFile.addText(9, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getColumnTime();
				excelFile.addText(10, i + 1, temp, leftStyle);

				temp = (String) orderExcel.getColumnNum();
				excelFile.addText(11, i + 1, temp, leftStyle);

			}
		}
		// 保存文件
		excelFile.getFile();
		/*
		Long detailcount = systemService.getCountForJdbcParam(countbf.append(queryDetail).toString()+")z");
		dataGrid.setResults(details);
		dataGrid.setTotal(detailcount.intValue());
		TagUtil.datagrid(response, dataGrid);*/
	}
	@RequestMapping(params = "exportExcel")
	public void exportExcel(BusinessOrderEntity businessOrder, HttpServletRequest request, HttpServletResponse response) throws Exception{
		String detailflag = request.getParameter("detailflag");
		if(null==detailflag||"".equals(detailflag)){
			detailflag = "1";
		}
		//默认页面的
		if(StringUtils.isBlank(businessOrder.getSysOrgCode())&&StringUtils.isBlank(businessOrder.getSysCompanyCode())){
			if("1"==request.getParameter("orgTypeInit")){
				businessOrder.setSysCompanyCode(request.getParameter("orgCodeInit"));
			}else if("0"==request.getParameter("orgTypeInit")){
				businessOrder.setSysOrgCode(request.getParameter("orgCodeInit"));
			}
		}
		Map<String,String> deptMap = new HashMap<>();
		StringBuffer queryDetail = new StringBuffer();
		StringBuffer detailbf = new StringBuffer();
		StringBuffer countbf = new StringBuffer();
		if("1".equals(detailflag)){
			countbf.append("select * from (select sum(o.ucost) from business_order o WHERE 1 = 1 ");
			detailbf.append("SELECT o.id,o.number AS number,o.sys_org_code AS sysOrgCode,o.user_name AS userName,o.user_card AS userCard,o.cost_type AS costType,o.ucost AS ucost,o.cost_addr AS costAddr,o.cost_putout AS costPutout,o.contribution AS contribution,o.sys_company_code AS sysCompanyCode,o.column_time AS columnTime,o.column_num AS columnNum FROM business_order o WHERE 1 = 1 ");
		}else{
			countbf.append("select sum(z.ucost) from (select sum(o.ucost) ucost  from business_order o WHERE 1 = 1 ");
			detailbf.append("SELECT max(o.id) id,max(o.number) AS number,max(o.sys_org_code) AS sysOrgCode,max(o.user_name) AS userName,max(o.user_card) AS userCard,max(o.cost_type) AS costType,cast(sum(o.ucost) as char) AS ucost,max(o.cost_addr) AS costAddr,max(o.cost_putout) AS costPutout,max(o.contribution) AS contribution,max(o.sys_company_code) AS sysCompanyCode,max(o.column_time) AS columnTime,cast(sum(cast(o.column_num as SIGNED)) as CHAR) AS columnNum FROM business_order o WHERE 1 = 1 ");
		}

		this.orgsql(queryDetail,request,deptMap);
		if(!StringUtils.isBlank(businessOrder.getSysOrgCode())){
			queryDetail.append(" and sys_org_code='"+businessOrder.getSysOrgCode()+"'");
		}
		if(!StringUtils.isBlank(businessOrder.getSysCompanyCode())){
			queryDetail.append(" and sys_company_code='"+businessOrder.getSysCompanyCode()+"'");
		}
		if(StringUtils.isBlank(businessOrder.getSysOrgCode())&&StringUtils.isBlank(businessOrder.getSysCompanyCode())){
			String orgCode = String.valueOf(null==request.getParameter("orgCode")?"":request.getParameter("orgCode"));
			String orgType = String.valueOf(null==request.getParameter("orgType")?"":request.getParameter("orgType"));
			if("0".equals(orgType)){
				queryDetail.append(" and sys_org_code='"+orgCode+"'");
			}else if("1".equals(orgType)){
				queryDetail.append(" and sys_company_code='"+orgCode+"'");
			}
		}
		if(!StringUtils.isEmpty(businessOrder.getCostType())){
			queryDetail.append(" and cost_type='"+businessOrder.getCostType()+"'");
		}
		//处理时间，当前月
		String startdt = request.getParameter("startdt");
		String enddt = request.getParameter("enddt");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		queryDetail.append(" and o.create_date >='").append(startdt).append("' ");
		queryDetail.append(" and o.create_date <='").append(enddt).append("' ");
		if("1".equals(detailflag)){
			queryDetail.append(" and o.uflag = 1 ");
		}else{
			queryDetail.append(" and o.uflag = 1 group by o.user_card ");
		}
		String execdetail = detailbf.append(queryDetail).toString();//.append(" limit ").append(dataGrid.getRows()*(dataGrid.getPage()-1)).append(",").append(dataGrid.getRows()).toString();
		List<BusinessOrderEntity> details = systemService.findObjForJdbc(execdetail,1,3000,BusinessOrderEntity.class);
		for(int i=0;i<details.size();i++){
			details.get(i).setSysOrgCode(deptMap.get(details.get(i).getSysOrgCode()));
			details.get(i).setSysCompanyCode(deptMap.get(details.get(i).getSysCompanyCode()));
		}
		Long detailcount = systemService.getCountForJdbcParam(countbf.append(queryDetail).toString()+")z");
		// 创建 Excel 文件， 文件名为打点信息， 表名为打点统计表
		CreateExcelFile excelFile = new CreateExcelFile("稿费演播费管理系统", startdt.substring(0,10)+"至"+enddt.substring(0,10)+(detailflag.equals("1")?"明细导出":"汇总导出"),
				request,response);
		// 设置单元格的右对齐格式
		HSSFCellStyle top = excelFile.createCellStyle();
		top.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		HSSFFont font1=excelFile.createFont();
		short height1=360;
		font1.setFontHeight(height1);
		top.setFont(font1);
		HSSFCellStyle topcenter = excelFile.createCellStyle();
		topcenter.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		HSSFFont font2=excelFile.createFont();
		font2.setFontHeight((short)260);
		topcenter.setFont(font2);
		HSSFCellStyle righttopcenter = excelFile.createCellStyle();
		righttopcenter.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
		righttopcenter.setFont(font2);
		// 设置单元格的左对齐格式
		HSSFCellStyle leftStyle = excelFile.createCellStyle();
		HSSFFont font3=excelFile.createFont();
		short height3=230;
		font3.setFontHeight(height3);
		leftStyle.setFont(font3);
		leftStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);

		leftStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
		//设置左边边框
		leftStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
		//设置右边边框
		leftStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
		//设置顶部边框
		leftStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
		HSSFCellStyle rightstyle = excelFile.createCellStyle();
		rightstyle.setFont(font3);
		rightstyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		rightstyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
		rightstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
		//设置左边边框
		rightstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
		//设置右边边框
		rightstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
		//设置顶部边框
		rightstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
		// 设置单元格的居中对齐文本格式
		HSSFCellStyle centerStyle = excelFile.createCellStyle();
		HSSFFont font=excelFile.createFont();
		short height=220;
		font.setFontHeight(height);
		centerStyle.setFont(font);
		centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		centerStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
		//设置左边边框
		centerStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
		//设置右边边框
		centerStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
		//设置顶部边框
		centerStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
		//设置行高度

		excelFile.setColWidth(0, 126);
		excelFile.mergeCells(0, 0, 10, 0);

		// 向Excel文件中的第一行添加表头
		if("1".equals(detailflag))
		{
			//excelFile.addText(0, 0,"青岛市广播电视台稿费、演播费发放明细表", top);
			excelFile.addText(0, 0,"青岛市广播电视台供稿劳务及演播劳务费发放明细表", top);
		}
		else
		{
			excelFile.addText(0, 0,"青岛市广播电视台供稿劳务及演播劳务费发放明细表", top);
		}
		excelFile.setColWidth(1, 126);
		excelFile.mergeCells(0, 1, 10, 1);
		// 向Excel文件中的第一行添加表头
		excelFile.addText(0, 1,"    发放单位:"+(StringUtil.isEmpty(businessOrder.getSysOrgCode())?"":deptMap.get(businessOrder.getSysOrgCode())), topcenter);

		excelFile.setColWidth(0, 4); //back 5  -1
		excelFile.setColWidth(1, 7);  //back8  -1
		excelFile.setColWidth(2, 22); //back23 -1
		excelFile.setColWidth(3, 9); //back 10 -1
		excelFile.setColWidth(4, 9);//back 10 -1
		excelFile.setColWidth(5, 20);
		excelFile.setColWidth(6, 9);
		excelFile.setColWidth(7, 15); //back 20  -5
		excelFile.setColWidth(8, 15); //back 16   -1
		excelFile.setColWidth(9, 11); //back 12   -1
		excelFile.setColWidth(10, 7);


		// 向Excel文件中的第一行添加表头
		excelFile.addText(0, 2,"序号", centerStyle);
		excelFile.setRowHieght(2, 26);
		/*		excelFile.addText(1, 2,"发放单位", centerStyle); */
		excelFile.addText(1, 2,"姓名", centerStyle);
		excelFile.addText(2, 2,"身份证号", centerStyle);

		excelFile.addText(3, 2,"费用名称", centerStyle);
		excelFile.addText(4, 2,"金额(元)", centerStyle);
		excelFile.addText(5, 2,"汇款地址或账号", centerStyle);
		excelFile.addText(6, 2,"发放方式", centerStyle);
		excelFile.addText(7, 2,"稿件题目(内容)", centerStyle);
		excelFile.addText(8, 2,"播出栏目", centerStyle);
		excelFile.addText(9, 2,"播出时间", centerStyle);
		excelFile.addText(10, 2,"字数", centerStyle);


		String temp = null;
		BusinessOrderEntity orderExcel=null;
		if (null != details && !(details.isEmpty())) {
			// 遍历检索结果列表，向 Excel 文件依次添加记录
			for (int i = 0; i < details.size(); i++) {
				orderExcel =  details.get(i);
				excelFile.setRowHieght(i+3, 16);
				temp = (i+1)+"";
				excelFile.addText(0, i + 3, temp, leftStyle);

				/*	temp = (String) orderExcel.getChanngelName();
					excelFile.addText(1, i + 3, temp, leftStyle);*/

				temp = (String) orderExcel.getUserName();
				excelFile.addText(1, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getUserCard();
				excelFile.addText(2, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getCostType();
				excelFile.addText(3, i + 3, temp, leftStyle);

				temp = String.valueOf(orderExcel.getUcost());
				excelFile.addText(4, i + 3, temp, rightstyle);

				temp = (String) orderExcel.getCostAddr();
				excelFile.addText(5, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getCostPutout();
				excelFile.addText(6, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getContribution();
				excelFile.addText(7, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getSysCompanyCode();
				excelFile.addText(8, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getColumnTime();
				excelFile.addText(9, i + 3, temp, leftStyle);

				temp = (String) orderExcel.getColumnNum();
				excelFile.addText(10, i + 3, temp, leftStyle);
			}
			excelFile.addText(1,details.size()+3,"合计：", topcenter);
			excelFile.addText(4,details.size()+3,detailcount.toString(), righttopcenter);
			// 向Excel文件中的第一行添加表头
			excelFile.addText(2,details.size()+5,"制单：", topcenter);
			excelFile.addText(3,details.size()+5,"编辑：", topcenter);
			excelFile.addText(5,details.size()+5,"制片人：", topcenter);
			excelFile.addText(6,details.size()+5,"部主任：", topcenter);
			excelFile.addText(8,details.size()+5,"批准：", topcenter);
			excelFile.addText(3,details.size()+7,"财务审核：", topcenter);
			excelFile.addText(8,details.size()+7,"     年           月", topcenter);
		}
		// 保存文件
		excelFile.getFile();
	}
	@RequestMapping(params = "doCheck")
	@ResponseBody
	public AjaxJson doCheck(BusinessOrderEntity businessOrder, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "稿费审核通过";
		BusinessOrderEntity t = businessOrderService.get(BusinessOrderEntity.class, businessOrder.getId());
		try {
			if(!CommonUtil.checkDay(t.getCreateDate(), SysContent.dayOut)){
				j.setMsg("已经超过审核时间,不能进行审核!");
				j.setSuccess(false);
				return j;
			}
			String ucost = businessOrder.getUcost();
			String ucolumnLev = businessOrder.getUcolumnLev();
			String uremark = businessOrder.getRemark();
			Date utime = new Date();
			String uFlag = "1";
			if("1"!=t.getUmodifyflag()){
				String modifyFlag = "1";
				if(t.getColumnLev().equals(ucolumnLev)&&t.getCost().equals(new BigDecimal(ucost)))
				{
					modifyFlag = "0";
				}
				t.setUmodifyflag(modifyFlag);
			}
			TSUser user = ResourceUtil.getSessionUser();
			this.combLog(t,ucost,ucolumnLev,user);
			t.setUcost(ucost);
			t.setUcolumnLev(ucolumnLev);
			t.setRemark(uremark);
			t.setUpdateDate(utime);
			t.setUflag(uFlag);
			t.setUpdateBy(user.getUserName());
			t.setUpdateName(user.getRealName());
			t.setAd1(CommonUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
			businessOrderService.saveOrUpdate(t);
			systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
		} catch (Exception e) {
			e.printStackTrace();
			message = "稿费表更新失败";
			j.setSuccess(false);
			j.setMsg(message);
			return j;
		}
		j.setMsg(message);
		return j;
	}

	private void combLog(BusinessOrderEntity o, String ucost, String ucolumnLev, TSUser user) {
		List<TSRoleUser> rUsers = systemService.findByProperty(TSRoleUser.class, "TSUser.id", user.getId());
		if (!CollectionUtils.isEmpty(rUsers)) {
			if(null==o.getULog()){
				o.setULog("");
			}
			String code = rUsers.get(0).getTSRole().getRoleCode();
			if ("checkm".equals(code)) {
				if (!(o.getCost().equals(new BigDecimal(ucost)) && o.getColumnLev().equals(ucolumnLev))) {
					String a = o.getULog() + "审核总监:" + user.getUserName() + "，在" + CommonUtil.getCurrentDate("yyyy-MM-dd");
					if (!o.getUcost().equals(new BigDecimal(ucost))) {
						a = a + "修改金额为：" + ucost + ".";
					}
					if (!o.getUcolumnLev().equals(ucolumnLev)) {
						a = a + "修改等级为：" + ucolumnLev + ".";
					}
					o.setULog(a);
				} else {
					o.setULog(o.getULog() + "审核总监:" + user.getUserName() + "于" + CommonUtil.getCurrentDate("yyyy-MM-dd") + "审核通过。");
				}
			} else if ("check".equals(code)) {
				if (!(o.getCost().equals(new BigDecimal(ucost)) && o.getColumnLev().equals(ucolumnLev))) {
					String a = o.getULog() + "审核人员:" + user.getUserName() + "，在" + CommonUtil.getCurrentDate("yyyy-MM-dd");
					if (!o.getCost().equals(new BigDecimal(ucost))) {
						a = a + "修改金额为：" + ucost + ".";
					}
					if (!o.getColumnLev().equals(ucolumnLev)) {
						a = a + "修改等级为：" + ucolumnLev + ".";
					}
					o.setULog(a);
				} else {
					o.setULog(o.getULog() + "审核人员:" + user.getUserName() + "于" + CommonUtil.getCurrentDate("yyyy-MM-dd") + "审核通过。");
				}
			} else if ("admin".equals(code)) {
				if (!(o.getCost().equals(new BigDecimal(ucost)) && o.getColumnLev().equals(ucolumnLev))) {
					String a = o.getULog() + "管理员:" + user.getUserName() + "，在" + CommonUtil.getCurrentDate("yyyy-MM-dd");
					if (!o.getCost().equals(new BigDecimal(ucost))) {
						a = a + "修改金额为：" + ucost + ".";
					}
					if (!o.getColumnLev().equals(ucolumnLev)) {
						a = a + "修改等级为：" + ucolumnLev + ".";
					}
					o.setULog(a);
				} else {
					o.setULog(o.getULog() + "管理员:" + user.getUserName() + "于" + CommonUtil.getCurrentDate("yyyy-MM-dd") + "审核通过。");
				}
			}
		}
	}
	private void orgCq(CriteriaQuery cq,HttpServletRequest request,Map<String,String> deptMap){
		String orgCode = String.valueOf(null==request.getParameter("orgCode")?"":request.getParameter("orgCode"));
		String orgType = String.valueOf(null==request.getParameter("orgType")?"":request.getParameter("orgType"));
		if("0".equals(orgType)){
			cq.eq("sysOrgCode",orgCode);
		}else if("1".equals(orgType)){
			cq.eq("sysCompanyCode",orgCode);
		}
		//查询条件组装器
		TSUser user = ResourceUtil.getSessionUser();
		String userId =user.getId();
		CriteriaQuery depteq = new CriteriaQuery(TSDepart.class);
		String queryDept = "select org_id from t_s_user_org where user_id=:userid";
		List<String> deptIds = systemService.getSession().createSQLQuery(queryDept).setString("userid",userId).list();
		if(deptIds!=null && deptIds.size()>0){
			Object values[] = deptIds.toArray();
			depteq.in("id", values);
		}else{
			depteq.eq("id","-1" );
		}
		List<String> deptCodes = new ArrayList<>();
		List<String> companyCodes = new ArrayList<>();
		depteq.add();
		List<TSDepart> departList =  this.systemService.getListByCriteriaQuery(depteq, false);
		for(TSDepart ts:departList){
			if("0".equals(ts.getOrgType())){
				deptCodes.add(ts.getOrgCode());
			}else if("1".equals(ts.getOrgType())){
				companyCodes.add(ts.getOrgCode());
			}
			if(null!=deptMap){
				deptMap.put(ts.getOrgCode(),ts.getDepartname());
			}
		}
		if(CollectionUtils.isEmpty(companyCodes)){
			cq.eq("sysCompanyCode", "-1");
		}
		if(!CollectionUtils.isEmpty(deptCodes)){
			Object values[] = deptCodes.toArray();
			cq.in("sysOrgCode", values);
		}
		if(!CollectionUtils.isEmpty(companyCodes)){
			Object values[] = companyCodes.toArray();
			cq.in("sysCompanyCode", values);
		}
	}
	private void orgsql(StringBuffer sql,HttpServletRequest request,Map<String,String> deptMap){
		//查询条件组装器
		TSUser user = ResourceUtil.getSessionUser();
		String userId =user.getId();
		CriteriaQuery depteq = new CriteriaQuery(TSDepart.class);
		String queryDept = "select org_id from t_s_user_org where user_id=:userid";
		List<String> deptIds = systemService.getSession().createSQLQuery(queryDept).setString("userid",userId).list();
		if(deptIds!=null && deptIds.size()>0){
			Object values[] = deptIds.toArray();
			depteq.in("id", values);
		}else{
			depteq.eq("id","-1" );
		}
		List<String> deptCodes = new ArrayList<>();
		List<String> companyCodes = new ArrayList<>();
		depteq.add();
		List<TSDepart> departList =  this.systemService.getListByCriteriaQuery(depteq, false);
		for(TSDepart ts:departList){
			if("0".equals(ts.getOrgType())){
				deptCodes.add(ts.getOrgCode());
			}else if("1".equals(ts.getOrgType())){
				companyCodes.add(ts.getOrgCode());
			}
			if(null!=deptMap){
				deptMap.put(ts.getOrgCode(),ts.getDepartname());
			}
		}
		if(CollectionUtils.isEmpty(companyCodes)){
			sql.append(" and sys_company_code = -1");
		}
		if(!CollectionUtils.isEmpty(deptCodes)){
			sql.append(" and sys_org_code in(");
			for(int i=0;i<deptCodes.size();i++){
				if(i==deptCodes.size()-1){
					sql.append("\"").append(deptCodes.get(i)).append("\")");
				}else{
					sql.append("\"").append(deptCodes.get(i)).append("\"").append(",");
				}
			}
		}
		if(!CollectionUtils.isEmpty(companyCodes)){
			sql.append(" and sys_company_code in(");
			for(int i=0;i<companyCodes.size();i++){
				if(i==companyCodes.size()-1){
					sql.append("\"").append(companyCodes.get(i)).append("\")");
				}else{
					sql.append("\"").append(companyCodes.get(i)).append("\"").append(",");
				}
			}
		}
	}
	/**
	 * 删除稿费订单表
	 * 
	 * @return
	 */
	@RequestMapping(params = "doDel")
	@ResponseBody
	public AjaxJson doDel(BusinessOrderEntity businessOrder, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		businessOrder = systemService.getEntity(BusinessOrderEntity.class, businessOrder.getId());
		message = "稿费删除成功";
		try{
			businessOrderService.delete(businessOrder);
			systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
		}catch(Exception e){
			e.printStackTrace();
			message = "稿费删除失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 批量删除稿费订单表
	 * 
	 * @return
	 */
	 @RequestMapping(params = "doBatchDel")
	@ResponseBody
	public AjaxJson doBatchDel(String ids,HttpServletRequest request){
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "稿费删除成功";
		try{
			for(String id:ids.split(",")){
				BusinessOrderEntity businessOrder = systemService.getEntity(BusinessOrderEntity.class, 
				id
				);
				businessOrderService.delete(businessOrder);
				systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
			}
		}catch(Exception e){
			e.printStackTrace();
			message = "稿费删除失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}


	/**
	 * 添加稿费订单表
	 * 
	 * @return
	 */
	@RequestMapping(params = "doAdd")
	@ResponseBody
	public AjaxJson doAdd(BusinessOrderEntity businessOrder, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "稿费添加成功";
		try{
			businessOrder.setCreateDate(new Date());
			businessOrder.setUflag("0");
			Map<String,String> myOrg = new HashMap<>();
			StringBuffer bf = new StringBuffer();
			this.orgsql(bf,null,myOrg);
			businessOrder.setAd2(myOrg.get(businessOrder.getSysOrgCode()));
			businessOrder.setAd3(myOrg.get(businessOrder.getSysCompanyCode()));
			businessOrderService.save(businessOrder);
			systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
		}catch(Exception e){
			e.printStackTrace();
			message = "稿费添加失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 更新稿费订单表
	 * 
	 * @return
	 */
	@RequestMapping(params = "doUpdate")
	@ResponseBody
	public AjaxJson doUpdate(BusinessOrderEntity businessOrder, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "稿费更新成功";
		BusinessOrderEntity t = businessOrderService.get(BusinessOrderEntity.class, businessOrder.getId());
		try {
			MyBeanUtils.copyBeanNotNull2Bean(businessOrder, t);
			businessOrderService.saveOrUpdate(t);
			systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
		} catch (Exception e) {
			e.printStackTrace();
			message = "稿费更新失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	

	/**
	 * 稿费订单表新增页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "goAdd")
	public ModelAndView goAdd(BusinessOrderEntity businessOrder, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(businessOrder.getId())) {
			businessOrder = businessOrderService.getEntity(BusinessOrderEntity.class, businessOrder.getId());
			req.setAttribute("businessOrderPage", businessOrder);
		}
		String orgCode = String.valueOf(null==req.getParameter("orgCode")?"":req.getParameter("orgCode"));
		String orgType = String.valueOf(null==req.getParameter("orgType")?"":req.getParameter("orgType"));
		String orgParent = String.valueOf(null==req.getParameter("orgParent")?"":req.getParameter("orgParent"));
		req.setAttribute("orgCode",orgCode);
		req.setAttribute("orgType",orgType);
		req.setAttribute("orgParent",orgParent);

		TSUser user = ResourceUtil.getSessionUser();
		String userId =user.getId();
		CriteriaQuery depteq = new CriteriaQuery(TSDepart.class);
		String queryDept = "select org_id from t_s_user_org where user_id=:userid";
		List<String> deptIds = systemService.getSession().createSQLQuery(queryDept).setString("userid",userId).list();
		if(deptIds!=null && deptIds.size()>0){
			Object values[] = deptIds.toArray();
			depteq.in("id", values);
		}else{
			depteq.eq("id","-1" );
		}
		List<String> deptCodes = new ArrayList<>();
		List<String> companyCodes = new ArrayList<>();
		depteq.add();
		List<TSDepart> departList =  this.systemService.getListByCriteriaQuery(depteq, false);
		for(TSDepart ts:departList){
			if("0".equals(ts.getOrgType())){
				deptCodes.add(ts.getOrgCode());
			}else if("1".equals(ts.getOrgType())){
				companyCodes.add(ts.getOrgCode());
			}
		}
		/*String querymax = "select max(number) from business_order where number is not null";
		Long max= systemService.getCountForJdbc(querymax);
		req.setAttribute("max",(null==max?0:max)+1);*/
		req.setAttribute("createDate",CommonUtil.getCurrentDate("yyyy-MM-dd"));
		req.setAttribute("userNa",user.getUserName());
		StringBuffer querycheckm =new StringBuffer();
		querycheckm.append("SELECT u.username FROM t_s_role_user t,t_s_role r,t_s_base_user u WHERE t.roleid = r.id AND t.userid = u.id AND u.ID IN ( SELECT o.user_id FROM t_s_user_org o,t_s_depart d WHERE o.org_id = d.id ");
		if(!CollectionUtils.isEmpty(deptCodes)){
			querycheckm.append(" and d.org_code in(");
			for(int i=0;i<deptCodes.size();i++){
				if(i==deptCodes.size()-1){
					querycheckm.append("\"").append(deptCodes.get(i)).append("\")");
				}else{
					querycheckm.append("\"").append(deptCodes.get(i)).append("\"").append(",");
				}
			}
		}else{
			querycheckm.append(" and d.org_code ='-1' ");
		}
		querycheckm.append("AND r.rolecode = 'checkm')");
		List<String> userList = systemService.getSession().createSQLQuery(querycheckm.toString()).list();
		if(!CollectionUtils.isEmpty(userList)){
			req.setAttribute("checkmuser",userList.get(0));
		}
		return new ModelAndView("com/jeecg/guangdian/businessOrder-add");
	}
	@RequestMapping(params = "goAddList")
	public ModelAndView goAddList(BusinessOrderEntity businessOrder, HttpServletRequest req) {
		String orgCode = String.valueOf(req.getParameter("orgCode"));
		String orgType = String.valueOf(req.getParameter("orgType"));
		req.setAttribute("orgCode",orgCode);
		req.setAttribute("orgType",orgType);
		req.setAttribute("startdt",req.getParameter("startdt"));
		req.setAttribute("enddt",req.getParameter("enddt"));
		return new ModelAndView("com/jeecg/guangdian/businessOrderAddList");
	}
	@RequestMapping(params = "goChart")
	public ModelAndView goChart(BusinessOrderEntity businessOrder, HttpServletRequest req) {
		String orgCode = String.valueOf(req.getParameter("orgCode"));
		String orgType = String.valueOf(req.getParameter("orgType"));
		req.setAttribute("orgCode",orgCode);
		req.setAttribute("orgType",orgType);
		req.setAttribute("startdt",req.getParameter("startdt"));
		req.setAttribute("enddt",req.getParameter("enddt"));
		return new ModelAndView("com/jeecg/guangdian/businessOrderChart");
	}
	/**
	 * 稿费订单表编辑页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "goUpdate")
	public ModelAndView goUpdate(BusinessOrderEntity businessOrder, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(businessOrder.getId())) {
			businessOrder = businessOrderService.getEntity(BusinessOrderEntity.class, businessOrder.getId());
			req.setAttribute("businessOrderPage", businessOrder);
		}
		return new ModelAndView("com/jeecg/guangdian/businessOrder-update");
	}
	
	/**
	 * 导入功能跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "upload")
	public ModelAndView upload(HttpServletRequest req) {
		req.setAttribute("controller_name","businessOrderController");
		return new ModelAndView("common/upload/pub_excel_upload");
	}
	
	/**
	 * 导出excel
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXlsBase")
	public String exportXlsBase(BusinessOrderEntity businessOrder,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
		CriteriaQuery cq = new CriteriaQuery(BusinessOrderEntity.class, dataGrid);
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, businessOrder, request.getParameterMap());
		List<BusinessOrderEntity> businessOrders = this.businessOrderService.getListByCriteriaQuery(cq,false);
		modelMap.put(NormalExcelConstants.FILE_NAME,"稿费表");
		modelMap.put(NormalExcelConstants.CLASS,BusinessOrderEntity.class);
		modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("稿费表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
			"导出信息"));
		modelMap.put(NormalExcelConstants.DATA_LIST,businessOrders);
		return NormalExcelConstants.JEECG_EXCEL_VIEW;
	}
	/**
	 * 导出excel
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXls")
	public String exportXls(BusinessOrderEntity businessOrder,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
		String startdt = request.getParameter("startdt");
		String enddt = request.getParameter("enddt");
		startdt =StringUtils.isEmpty(startdt)?CommonUtil.getCurrentDate("yyyy-MM-01")+" 00:00:00":startdt+" 00:00:00";
		enddt = StringUtils.isEmpty(enddt)?CommonUtil.getCurrentDate("yyyy-MM-dd")+" 23:59:59":enddt+" 23:59:59";
		CriteriaQuery cq = new CriteriaQuery(BusinessOrderEntity.class, dataGrid);
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, businessOrder, request.getParameterMap());
		Map<String,String> deptMap = new HashMap<>();
		this.orgCq(cq,request,deptMap);
		cq.gt("createDate", CommonUtil.strToDateLong(startdt));
		cq.lt("createDate",CommonUtil.strToDateLong(enddt));
		cq.eq("uflag", "1");
		cq.addOrder("number", SortDirection.asc);
		cq.add();
		List<BusinessOrderEntity> businessOrders = this.businessOrderService.getListByCriteriaQuery(cq,false);
		try{
			CreateExcelFile excelFile = new CreateExcelFile("稿费演播费管理系统", startdt.substring(0,10)+"至"+enddt.substring(0,10)+"明细导出",
					request,response);
			// 设置单元格的右对齐格式
			HSSFCellStyle rightStyle = excelFile.createCellStyle();
			rightStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			// 设置单元格的左对齐格式
			HSSFCellStyle leftStyle = excelFile.createCellStyle();
			leftStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
			// 设置单元格的居中对齐文本格式
			HSSFCellStyle centerStyle = excelFile.createCellStyle();
			centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 设置列宽
			excelFile.setColWidth(0, 5);
			excelFile.setColWidth(1, 25);
			excelFile.setColWidth(2, 25);
			excelFile.setColWidth(3, 25);
			excelFile.setColWidth(4, 25);
			excelFile.setColWidth(5, 25);
			excelFile.setColWidth(6, 25);
			excelFile.setColWidth(7, 25);
			excelFile.setColWidth(8, 25);
			excelFile.setColWidth(9, 25);
			excelFile.setColWidth(10, 25);
			excelFile.setColWidth(11, 25);
			/*excelFile.setColWidth(12, 25);
			excelFile.setColWidth(13, 25);
			excelFile.setColWidth(14, 25);
			excelFile.setColWidth(15, 25);
			excelFile.setColWidth(16, 25);
			excelFile.setColWidth(17, 25);
			excelFile.setColWidth(18, 25);
			excelFile.setColWidth(19, 25);*/
			// 向Excel文件中的第一行添加表头
			excelFile.addText(0, 0,"序号", centerStyle);
			excelFile.addText(1, 0,"频道名称", centerStyle);
			excelFile.addText(2, 0,"姓名", centerStyle);
			excelFile.addText(3, 0,"身份证号", centerStyle);

			excelFile.addText(4, 0,"费用类型", centerStyle);
			excelFile.addText(5, 0,"金额", centerStyle);
			excelFile.addText(6, 0,"汇款地址/账号", centerStyle);
			excelFile.addText(7, 0,"发放方式", centerStyle);
			excelFile.addText(8, 0,"稿件题目(内容)", centerStyle);
			excelFile.addText(9, 0,"栏目名称", centerStyle);
			excelFile.addText(10, 0,"播出时间", centerStyle);
			excelFile.addText(11, 0,"字数/时长/版面", centerStyle);
			/*excelFile.addText(12, 0,"等级", centerStyle);
			excelFile.addText(13, 0,"制单人", centerStyle);
			excelFile.addText(14, 0,"编辑", centerStyle);
			excelFile.addText(15, 0,"制片人", centerStyle);
			excelFile.addText(16, 0,"高管主任", centerStyle);
			excelFile.addText(17, 0,"部主任", centerStyle);
			excelFile.addText(18, 0,"备注", centerStyle);
			excelFile.addText(19, 0,"录入时间", centerStyle); */

			String temp = null;
			BusinessOrderEntity orderExcel=null;
			if (!(businessOrders.isEmpty())) {
				// 遍历检索结果列表，向 Excel 文件依次添加记录
				for (int i = 0; i < businessOrders.size(); i++) {
					orderExcel =  businessOrders.get(i);

					temp = (String) orderExcel.getNumber();
					excelFile.addText(0, i + 1, temp, centerStyle);

					temp = (String) deptMap.get(orderExcel.getSysCompanyCode());
					excelFile.addText(1, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getUserName();
					excelFile.addText(2, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getUserCard();
					excelFile.addText(3, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getCostType();
					excelFile.addText(4, i + 1, temp, leftStyle);

					temp = String.valueOf(orderExcel.getCost());
					excelFile.addText(5, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getCostAddr();
					excelFile.addText(6, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getCostPutout();
					excelFile.addText(7, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getContribution();
					excelFile.addText(8, i + 1, temp, leftStyle);

					temp = (String)  deptMap.get(orderExcel.getSysOrgCode());
					excelFile.addText(9, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getColumnTime();
					excelFile.addText(10, i + 1, temp, leftStyle);

					temp = (String) orderExcel.getColumnNum();
					excelFile.addText(11, i + 1, temp, leftStyle);
				}
			}
			excelFile.getFile();
		}catch (Exception e){
		}finally {
		}
		return null;
	}
	/**
	 * 导出excel 使模板
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXlsByT")
	public String exportXlsByT(BusinessOrderEntity businessOrder,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
    	modelMap.put(NormalExcelConstants.FILE_NAME,"稿费表");
    	modelMap.put(NormalExcelConstants.CLASS,BusinessOrderEntity.class);
    	modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("稿费表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
    	"导出信息"));
    	modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
    	return NormalExcelConstants.JEECG_EXCEL_VIEW;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(params = "importExcel", method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			try {
				List<BusinessOrderEntity> listBusinessOrderEntitys = ExcelImportUtil.importExcel(file.getInputStream(),BusinessOrderEntity.class,params);
				for (BusinessOrderEntity businessOrder : listBusinessOrderEntitys) {
					businessOrderService.save(businessOrder);
				}
				j.setMsg("文件导入成功！");
			} catch (Exception e) {
				j.setMsg("文件导入失败！");
				logger.error(e.getMessage());
			}finally{
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return j;
	}

	/**
	 * 获取部门
	 * @param req
	 * @return
	 */
	@RequestMapping(params = "getDeptList")
	@ResponseBody
	public AjaxJson getDeptList(HttpServletRequest req) {
		AjaxJson j = new AjaxJson();
		try {
			TSUser user = ResourceUtil.getSessionUser();
			String userId =user.getId();
			CriteriaQuery depteq = new CriteriaQuery(TSDepart.class);
			String queryDept = "select org_id from t_s_user_org where user_id=:userid";
			List<String> deptIds = systemService.getSession().createSQLQuery(queryDept).setString("userid",userId).list();
			if(deptIds!=null && deptIds.size()>0){
				Object values[] = deptIds.toArray();
				depteq.in("id", values);
			}else{
				depteq.eq("id","-1" );
			}
			List<TSDepart> deptCodes = new ArrayList<>();
			List<TSDepart> companyCodes = new ArrayList<>();
			depteq.add();
			List<TSDepart> departList =  this.systemService.getListByCriteriaQuery(depteq, false);
			for(TSDepart ts:departList){
				if("0".equals(ts.getOrgType())){
					deptCodes.add(ts);
				}else if("1".equals(ts.getOrgType())){
					companyCodes.add(ts);
				}
			}
			//将List转换成JSON存储
			JSONArray dept = new JSONArray();
			if(deptCodes!=null && deptCodes.size()>0){
				for(int i=0;i<deptCodes.size();i++){
					JSONObject jsonParts = new JSONObject();
					jsonParts.put("code", deptCodes.get(i).getOrgCode());
					jsonParts.put("name", deptCodes.get(i).getDepartname());
					dept.add(jsonParts);
				}
			}
			JSONArray comp = new JSONArray();
			if(companyCodes!=null && companyCodes.size()>0){
				for(int i=0;i<companyCodes.size();i++){
					JSONObject jsonParts = new JSONObject();
					jsonParts.put("code", companyCodes.get(i).getOrgCode());
					jsonParts.put("name", companyCodes.get(i).getDepartname());
					jsonParts.put("parentCode", companyCodes.get(i).getTSPDepart().getOrgCode());
					comp.add(jsonParts);
				}
			}
			Map<String,Object> attrs = new HashMap<String, Object>();
			attrs.put("dept", dept);
			attrs.put("comp", comp);
			j.setAttributes(attrs);
		} catch (Exception e) {
			j.setSuccess(false);
			e.printStackTrace();
		}
		return j;
	}
	/**
	 * 稿费订单表列表 页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "tocheck")
	public ModelAndView tocheck(HttpServletRequest request) {
		String orgCode = String.valueOf(request.getParameter("orgCode"));
		String orgType = String.valueOf(request.getParameter("orgType"));
		String orgParent = String.valueOf(null==request.getParameter("orgParent")?"":request.getParameter("orgParent"));
		request.setAttribute("orgCode",orgCode);
		request.setAttribute("orgType",orgType);
		request.setAttribute("orgParent",orgParent);
		TSUser user = ResourceUtil.getSessionUser();
		List<TSRoleUser> rUsers = systemService.findByProperty(TSRoleUser.class, "TSUser.id", user.getId());
		if(!CollectionUtils.isEmpty(rUsers)){
			String code = rUsers.get(0).getTSRole().getRoleCode();
			//查全部
			if("admin".equals(code)){
			}if("check".equals(code)){
				//默认没时间
			}else if("checkm".equals(code)){
				//上个月1号到这个月
				request.setAttribute("stdt",CommonUtil.getoutstartday(SysContent.dayOut));
				request.setAttribute("eddt",CommonUtil.getCurrentDate("yyyy-MM-dd"));
			}else{
			}
			request.setAttribute("userrole",code);
		}
		return new ModelAndView("com/jeecg/guangdian/businessOrderCheck");
	}
	/**
	 * 稿费订单表列表 页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "toexport")
	public ModelAndView toexport(HttpServletRequest request) {
		String orgCode = String.valueOf(request.getParameter("orgCode"));
		String orgType = String.valueOf(request.getParameter("orgType"));
		String orgParent = String.valueOf(null==request.getParameter("orgParent")?"":request.getParameter("orgParent"));
		request.setAttribute("orgCode",orgCode);
		request.setAttribute("orgType",orgType);
		request.setAttribute("orgParent",orgParent);
		request.setAttribute("detailflag",request.getParameter("detailflag"));
		request.setAttribute("startdt",request.getParameter("startdt"));
		request.setAttribute("enddt",request.getParameter("enddt"));
		return new ModelAndView("com/jeecg/guangdian/businessOrderExport");
	}
	@RequestMapping(params = "totopcheck")
	public ModelAndView totopcheck(HttpServletRequest request) {
		String orgCode = String.valueOf(request.getParameter("orgCode"));
		String orgType = String.valueOf(request.getParameter("orgType"));
		String orgParent = String.valueOf(null==request.getParameter("orgParent")?"":request.getParameter("orgParent"));
		request.setAttribute("orgCode",orgCode);
		request.setAttribute("orgType",orgType);
		request.setAttribute("orgParent",orgParent);
		request.setAttribute("detailflag",request.getParameter("detailflag"));
		request.setAttribute("startdt",request.getParameter("startdt"));
		request.setAttribute("enddt",request.getParameter("enddt"));
		return new ModelAndView("com/jeecg/guangdian/businessOrderTopCheck");
	}
}
